import { isString } from "./is";


export function toSuccess(data: any) {
    return { success: true, message: 'okd', data }
}

export function toError(e: any) {
    if (isErrors(e)) {
        return { success: false, message: 'fail', data: e.errors }
    }
    if (isError(e)) {
        return { success: false, message: e.message, data: { stack: e.stack } }
    }
    if (isString(e)) {
        return { success: false, message: e }
    }
    return { success: false, message: 'fail', data: e }
}
export interface IErrors {
    errors: Error;
}
export function isErrors(e: any): e is IErrors {
    return Reflect.has(e, 'errors')
}
export function isError(e: any): e is Error {
    return e instanceof Error;
}